<?php

namespace app\admin\controller\information;

use app\common\controller\Backend;

/**
 * 日志管理
 *
 * @icon fa fa-circle-o
 */
class Actionlog extends Backend
{
    /**
     * U8user模型对象
     * @var \app\admin\model\information\U8user
     */
    protected $model = null;
    protected $searchFields = "username,action,result,url";
    protected $noNeedLogin = [];
    
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\information\Actionlog;
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
    }
    
    public function index()
    {
        if (false === $this->request->isAjax()) {
            return $this->view->fetch();
        }
        //如果发送的来源是 Selectpage，则转发到 Selectpage
        if ($this->request->request('keyField')) {
            return $this->selectpage();
        }
        
        [$where, $sort, $order, $offset, $limit] = $this->buildparams();
        
        $list = $this->model
        ->where($where)
        ->order($sort, $order)
        ->paginate($limit);
        
        $result = ['total' => $list->total(), 'rows' => $list->items()];
        return json($result);
    }
    
    /**
     * 详情
     */
    public function detail($ids)
    {
        $row = $this->model->get(['id' => $ids]);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        
        $this->view->assign("row",$row->toArray());
        return $this->view->fetch();
    }
}
